package com.tql.stackTest;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> integers = new LinkedList<Integer>();
        integers.addFirst(1);
        integers.addFirst(2);
        Integer poll = integers.poll();
        System.out.println(poll);
        System.out.println(integers);
    }
    /*
    *
    * 232. 用栈实现队列
    * */
    class MyQueue {
        private Stack<Integer> inStack;;
        private Stack<Integer> outStack;
        public MyQueue() {
            inStack=new Stack<Integer>();
            outStack=new Stack<Integer>();
        }

        public void push(int x) {
            inStack.push(x);
        }

        public int pop() {
            if(outStack.isEmpty()){
                in2out();
            }
            return outStack.pop();
        }

        public int peek() {
            if(outStack.isEmpty()){
                in2out();
            }
            return outStack.peek();
        }

        public boolean empty() {
           return inStack.isEmpty()&&outStack.isEmpty();
        }
        public void in2out(){
            while(!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
    }
//    public static String decodeString(String s) {
//
//    }
}
